import { $http } from '@/utils';
import { $ResponseCode } from '@/utils/const/env';
export const Orders = {
    list(query: any) {
        return new Promise((resolve, reject) => {
            $http.get('Orders/list', {
                data: query
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    create: (data: any) => {
        return new Promise((resolve, reject) => {
            $http.post('Orders/create', {
                data
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else if (res.code === $ResponseCode.PAY_SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            });
        });
    },
    payByOrders(data: any) {
        return new Promise((resolve, reject) => {
            $http.post('Orders/payByOrders', {
                data
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else if (res.code === $ResponseCode.PAY_SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            });
        });
    },
    cancel: (trade: any) => {
        return new Promise((resolve, reject) => {
            $http.get('Orders/cancel', {
                data: {
                    trade
                }
            }).then((res: any) => {
                resolve(res);
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            });
        });
    },
    delete: (trade: any) => {
        return new Promise((resolve, reject) => {
            $http.get('Orders/delete', {
                data: {
                    trade
                }
            }).then((res: any) => {
                resolve(res);
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            });
        });
    },
    getOrderState: (trade: any) => {
        return new Promise((resolve, reject) => {
            $http.get('Orders/getOrderState', {
                data: {
                    trade
                }
            }).then((res: any) => {
                resolve(res);
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            });
        });
    },
    info: (options: any) => {
        let query: any = {};
        if (typeof options === 'string') {
            query.trade = options;
        } else {
            query = options;
        }
        return new Promise((resolve, reject) => {
            $http.get('Orders/info', {
                data: query
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            });
        });
    },
    refund: (data: any) => {
        return new Promise((resolve, reject) => {
            $http.post('Orders/refund', {
                data
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else if (res.code === $ResponseCode.PAY_SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            });
        });
    },
    transferring: (data: any) => {
        return new Promise((resolve, reject) => {
            $http.post('Orders/transferring', {
                data
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else if (res.code === $ResponseCode.PAY_SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            });
        });
    }
}